<template>
  <el-dialog
    title="分配案件"
    :visible.sync="visible"
    :modal="false"
    :close-on-click-modal="false"
    :modal-append-to-body="false"
    width="40%"
  >
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="处理人">
        <el-select
          size="small"
          v-model="form.deal_admin_id"
          placeholder="请选择"
        >
          <el-option
            v-for="item in dealUser"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <!-- 
      <el-form-item label="处理建议">
        <el-input type="textarea" v-model="form.deal_desc"></el-input>
      </el-form-item>

      <el-form-item label="审核人">
        <el-select
          size="small"
          v-model="form.audit_admin_id"
          placeholder="请选择"
        >
          <el-option
            v-for="item in auditUser"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="审核建议">
        <el-input type="textarea" v-model="form.audit_desc"></el-input>
      </el-form-item> -->

      <el-form-item>
        <el-button size="small" @click="cancel">取消</el-button>
        <el-button type="primary" size="small" @click="submit">分配</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
export default {
  props: [],
  data() {
    return {
      // 要提交的参数
      item: {},
      form: {},

      dealUser: [],
      auditUser: [],

      // 菜单表单
      loading: false,
      visible: false,
      submiting: false,

      limit: 10,
      current_page: 1,
      total: 1,
      tableLoading: false,
      list: []
    }
  },
  methods: {
    show(row) {
      this.form = {}
      this.visible = true
      this.item = row
      this.getDealUser()
      console.log(row)
    },
    getDealUser() {
      this.$api.system.role
        .getUser({
          data: {
            id: 60
          }
        })
        .then(response => {
          this.dealUser = response.data.data.right
        })
        .catch(error => {
          this.$message.error(error)
        })

      this.$api.system.role
        .getUser({
          data: {
            id: 61
          }
        })
        .then(response => {
          this.auditUser = response.data.data.right
        })
        .catch(error => {
          this.$message.error(error)
        })
    },
    submit() {
      this.form.id = this.item.id
      console.log(this.form)

      this.$api.alarm
        .casesDispatch({
          data: this.form
        })
        .then(res => {
          console.log(res)
          if (res.data.code === 0) {
            this.visible = false
            this.$emit('close')
          } else {
            this.$message.error(res.data.message)
          }
        })
        .catch(error => {
          this.$message.error(error)
        })
    },
    fetchList(id) {
      this.tableLoading = true
      this.$api.alarm
        .approval({
          data: {
            cases_id: id
          }
        })
        .then(res => {
          this.list = res.data.data.list
          this.total = +res.data.data.count
          this.tableLoading = false
        })
    },
    cancel() {
      this.visible = false
    }
  }
}
</script>
<style lang="postcss" scoped>
.el-form-item {
  margin-bottom: 5px;
}
</style>
